package vn.vfriends.payment.service.impl;

import java.util.Date;
import java.util.List;
import javax.inject.Inject;
import vn.vfriends.payment.jpa.controller.AccountJpaController;
import vn.vfriends.payment.jpa.entity.Account;
import vn.vfriends.payment.jpa.entity.Transaction;
import vn.vfriends.payment.service.AccountService;

/**
 *
 * @author tuan@vfriends.vn
 */
public class AccountServiceImpl implements AccountService {

    @Inject private AccountJpaController accountController;
    
    @Override
    public Account generateCIF(Long userId, Long initAmount) throws Exception {
        return accountController.generateCIF(userId, initAmount);
    }

    @Override
    public Account resetAccount(Long userId, Long initAmount) throws Exception {
        return accountController.resetAccount(userId, initAmount);
    }

    @Override
    public Account findAccountByCif(String cif) {
        return accountController.findAccountByCif(cif);
    }

    @Override
    public List<Transaction> getTransactions(String cif, String type, Date fromDate, Date toDate) throws Exception {
        Account account = accountController.findAccountByCif(cif);
        Transaction.Type transactionType = null;
        if (type != null && type.equals("OUT")) {
            transactionType = Transaction.Type.OUT;
        } else if (type.equals("IN")) {
            transactionType = Transaction.Type.IN;
        }

        return accountController.findTransactions(account, transactionType, fromDate, toDate);
    }

}
